<template>
  <div class="app-container">
    <el-row :gutter="20" class="mb8">
      <el-col :span="1.5">
        <el-button round icon="el-icon-back" @click="goBack">返回</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button-group>
          <el-button type="primary" @click="handleSave">保存</el-button>
          <el-button type="danger" @click="handleDelete">删除</el-button>
          <el-button @click="handleReject">拒检</el-button>
          <el-button @click="handleReset">重置</el-button>
        </el-button-group>
      </el-col>
      <el-col :span="1.5">
        <el-button-group>
          <el-button @click="handleAddReview">新增复查</el-button>
          <el-button @click="handleViewReview">复查记录</el-button>
        </el-button-group>
      </el-col>
    </el-row>
    <el-divider></el-divider>
    <el-row :gutter="20">
      <!-- 体检人信息描述 -->
      <el-col :span="4">
        <usr-info></usr-info>
      </el-col>
      <!-- tab 项目 -->
      <el-col :span="20">
        <table-form></table-form>
      </el-col>
    </el-row>

    <!-- 新增复查 对话框 -->
    <el-dialog
      :title="reviewTitle"
      :visible.sync="reviewOpen"
      width="600px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form
        ref="reviewForm"
        :model="reviewForm"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="复查项目" prop="projectId">
          <el-select
            v-model="reviewForm.projectId"
            placeholder="请选择复查项目"
            style="width: 100%"
          >
            <el-option
              v-for="item in reviewProjectList"
              :key="item.projectId"
              :label="item.projectName"
              :value="item.projectId"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="复查原因" prop="reviewReason">
          <el-input
            v-model="reviewForm.reviewReason"
            placeholder="请输入复查原因"
            type="textarea"
            :rows="5"
            style="width: 100%"
            clearable
            maxlength="200"
            show-word-limit
          />
        </el-form-item>
        <el-form-item label="复查时间" prop="reviewTime">
          <el-date-picker
            v-model="reviewForm.reviewTime"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd"
            style="width: 100%"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitReviewForm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
    <!-- 复查记录 -->
    <el-dialog
      :title="reviewRecordTitle"
      :visible.sync="reviewRecordOpen"
      width="900px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-table v-loading="loading" :data="reviewList" highlight-current-row>
        <el-table-column label="检查项目" align="center" prop="projectName" />
        <el-table-column label="复查原因" align="center" prop="reviewReason" />
        <el-table-column label="复查时间" align="center" prop="reviewTime" />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import UsrInfo from "../components/UsrInfo";
import TableForm from "../components/TableForm";
export default {
  name: "editForm",
  components: {
    UsrInfo,
    TableForm,
  },
  props: {},
  data() {
    return {
      // 遮罩层
      loading: false,
      // 新增复查对话框标题
      reviewTitle: undefined,
      // 新增复查对话框是否显示弹出层
      reviewOpen: false,
      // 新增复查表单参数
      reviewForm: {},
      // 复查记录对话框标题
      reviewRecordTitle: undefined,
      // 复查记录对话框是否显示弹出层
      reviewRecordOpen: false,
      // 表单校验
      rules: {
        projectId: [
          {
            required: true,
            message: "复查项目不能为空",
            trigger: "blur",
          },
        ],
        reviewReason: [
          {
            required: true,
            message: "复查原因不能为空",
            trigger: "blur",
          },
        ],
        reviewTime: [
          {
            required: true,
            message: "复查时间不能为空",
            trigger: "blur",
          },
        ],
      },
      // 复查记录
      reviewList: [
        {
          projectName: "1",
          reviewReason: "222",
          reviewTime: "2020",
        },
        {
          projectName: "1",
          reviewReason: "222",
          reviewTime: "2020",
        },
        {
          projectName: "1",
          reviewReason: "222",
          reviewTime: "2020",
        },
      ],
      // 复查项目列表
      reviewProjectList: [
        {
          projectId: "111",
          projectName: "你的",
          reviewReason: "222",
          reviewTime: "2020",
        },
      ],
    };
  },
  methods: {
    // 返回
    goBack() {
      this.$router.back();
    },
    // 保存
    handleSave() {},
    // 删除
    handleDelete() {
      console.log("删除", this.$route.query.registerId);
      const ids = this.$route.query.registerId;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          // return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    // 拒检
    handleReject() {
      console.log("删除", this.$route.query.registerId);
      const ids = this.$route.query.registerId;
      this.$modal
        .confirm("是否确认拒检？")
        .then(function () {
          // return delProject(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("拒检成功");
        })
        .catch(() => {});
    },
    // 重置
    handleReset() {},
    // 新增复查
    handleAddReview() {
      this.reset();
      this.reviewOpen = true;
      this.reviewTitle = "新增复查";
    },
    // 查看复查记录
    handleViewReview() {
      this.reset();
      this.reviewRecordOpen = true;
      this.reviewRecordTitle = "复查记录";
    },
    // 取消按钮
    cancel() {
      this.reviewOpen = false;
      this.reviewRecordOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.reviewForm = {
        id: undefined,
        projectId: undefined,
        reviewReason: undefined,
        reviewTime: undefined,
      };
      this.resetForm("reviewForm");
    },
    // 新增复查提交
    submitReviewForm() {
      console.log(this.reviewForm);
    },
  },
};
</script>

<style>
</style>